<template>
	<view class="page">
		<view class="title">{{ respond.tempName }}</view>
		<view class="content">
			<view class="txt_remind">
				为了给您提供更好的服务，希望您能用几分钟时间，将您的感受和建议告诉我们，我们非常重视您的宝贵意见！
			</view>
			<view class="txt_doctor">
				<view>发布医生：{{ respond.doctorName }}</view>
				<view>{{ respond.createdTime }}</view>
			</view>
			<view class="txt_doctor">（{{ respond.num }}/{{ respond.totalNum }}期次）</view>

			<view class="question" v-for="(item, index) in formVoList" :key="index">

				<view class="title_item">{{ index + 1 }}<span v-if="item.required">*</span>.{{ item.problemName }}
				</view>
				<!-- 单选 -->
				<view v-if="item.type == 1">
					<view class="checkbox_time" v-for="(value, index2) in item.options" :key="index2">
						<view class="checkbox_wrap">
							<view class="checkbox_circle">
								<view v-if="item.answers.includes(value)"></view>
							</view>
						</view>
						<view>{{ value }}</view>
					</view>
				</view>
				<!-- 复选 -->
				<view v-if="item.type == 2">
					<view class="checkbox_time" v-for="(value, index2) in item.options" :key="index2">
						<view class="checkbox_wrap">
							<view class="checkbox_circle many">
								<view v-if="item.answers.includes(value)"></view>
							</view>
						</view>
						<view>{{ value }}</view>
					</view>
				</view>
				<!-- 填空 -->
				<view v-if="item.type == 3">
					<view class="input_time">
						<text>{{ item.answers[0] }}</text>
						<!-- <textarea type="text" v-model="item.answers[0]"></textarea> -->
						<!-- <input type="text"> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			respond: {
				id: '',
				tempName: '',
				doctorName: '',
				createdTime: '',
				num: 0,
				totalNum: 0,
				writeStatus: 0 //0未填写   1已填写
			},
			formVoList: []
		}
	},
	onLoad(options) {
		this.id = options.id
	},
	onShow() {
		this.getUserFollowParticulars()
	},
	methods: {
		// 获取问卷详情
		getUserFollowParticulars() {
			this.$api.getUserFollowParticulars({ id: this.id }).then(e => {
				const { code, result } = e
				if (code == 200) {
					this.formVoList = result.formVoList
					this.formVoList.forEach(item => {
						if (!item.answers) {
							item.answers = []
						}
					});
					for (let i in this.respond) {
						this.respond[i] = result[i]
					}
				} else {
					uni.showToast({
						title: e.message,
						icon: 'none'
					});
				}
			})
		},
		// 单选
		single(index, value) {
			this.formVoList[index].answers = [value]
			this.$forceUpdate()
		},
		// 复选
		many(index, value) {
			const index_ = this.formVoList[index].answers.indexOf(value)
			if (index_ != -1) {  //是否有此选项
				this.formVoList[index].answers.splice(index_, 1)
			} else {
				this.formVoList[index].answers.push(value)
			}
			this.$forceUpdate()
		},
	}
}
</script>

<style lang="less" scoped>
@import './followDetail.less';
</style>
